package cn.psvmc.cxzapi.controller.customer;

import cn.psvmc.cxzapi.model.common.OrderEntity;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.customer.TCustomerAuthService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description 授权管理
 * @Author ywx
 * Date 2024/8/16 22:06
 **/
@RestController
@RequestMapping("/auth")
public class TCustomerAuthController {
    @Resource
    private TCustomerAuthService customAuthService;

    /**
     * @Description 生成授权书并上传至oss
     * @Date 2024/8/17 10:30
     * @Author YWX
     * @Param [authPeople]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @GetMapping("/pdf")
    public Result generatePdf(@RequestParam("name") String name) {
        ToolUtils.validation(new Object[]{
                name, "姓名", 2
        });
        return ResultGenerator.genSuccessResult("上传成功！", customAuthService.upPdfToOss(name));
    }

    /**
     * @Description 获取信审报告
     * @Date 2024/8/17 10:50
     * @Author YWX
     * @Param [map]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/get_risk_report")
    public Result getRiskReport(@RequestBody Map<String, Object> map) {
        ToolUtils.validation(new Object[]{
                map.get("name"), "姓名", 2
                , map.get("ident_number"), "身份证号", 2
                , map.get("phone"), "手机号", 2
        });
        return customAuthService.getRiskReport(map);
    }

    /**
     * @Description 生成信审报告
     * @Date 2024/9/6 8:29
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/generate_report")
    public Result generateReport(@RequestBody OrderEntity entity) {
        Integer orderId = entity.getOrderId();
        ToolUtils.validation(new Object[]{
                orderId, "订单id", 1
        });
        return customAuthService.generateReport(orderId);
    }
}
